package scalaLearning.scalaBasic

trait Listen{
  val name: String
  def listen() = {
    println("You friend " + name + " is listening")
  }
}

trait Read{
  val name: String
  def read() = {
    println("You friend " + name + " is reading")
  }
}

trait Speak{
  val name: String
  def speak() = {
    println("You friend " + name + " is speaking.")
  }
}

class Human(val name : String){
  def listen() = {
    println(name + " is listening.")
  }
}

class Animal(val name: String){
}
//Animal 里面有name这个名字，现在Cat又有个名字name 重名了，因此需要加 override
class Cat(override val name: String) extends Animal(name: String) with Speak with Listen with Read{//trait类似于java里面的接口，但是不同的是他里面可以写出方法的实现部分
  override def toString(): String = " hello "+name+"! "//谁都有toString()方法，你要自己写一个的话要override
}

class Cat1(override val name: String) extends  Speak with Listen with Read{
override def toString(): String = " hello "+name+"! "
}


object TestFriend {
  def main(args: Array[String]) {
    //    		val f1 = new Listen();//java 接口很像 不能直接够造

        val h1 = new Human("gaga");
           h1.listen();

    //这样scat就是Friend了
    val scat = new Cat("hello kitty")
    scat.listen();
    scat.speak()
    println(scat)//肯定会调用 toString方法
  }
}
